package com.example.assignment01_javaee.Controller;

import com.example.assignment01_javaee.Entity.Admin;
import com.example.assignment01_javaee.Service.AdminService;
import com.example.assignment01_javaee.Utils.JwtUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("/admin")
public class AdminController {
    @Autowired
    AdminService adminService;

    @PostMapping("/login")
    public Admin login(Admin admin){
        String adminname = admin.getAdminname();
        String adminpassword = admin.getAdminpassword();
        Admin admin1 = adminService.login(adminname,adminpassword);
        if (admin1==null){
            return null;
        }else{
            admin.setAdmintoken(JwtUtil.createToken());
            return admin;
        }
    }

}
